﻿using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace Collab.Services.Remote
{
    public static class CollaborationBinding
    {
        /// <summary>
        /// Creates a TcpBinding with Teredo enabled
        /// </summary>
        /// <returns></returns>
        public static Binding CreateCollaborationBinding()
        {            
            NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
            binding.ReliableSession.Enabled = true;
            binding.ReliableSession.Ordered = true;
            var elems = binding.CreateBindingElements();
            foreach (var item in elems)
            {
                if (item is TcpTransportBindingElement)                
                    (item as TcpTransportBindingElement).TeredoEnabled = true;                
                else if (item is ReliableSessionBindingElement)                
                    Debug.WriteLine("RELIABLE:" + (item as ReliableSessionBindingElement).Ordered);                
            }
            return new CustomBinding(elems);
        }

    }
}
